<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
                template="/resources/template/template.xhtml"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns="http://www.w3.org/1999/xhtml"
                xmlns:pe="http://primefaces.org/ui/extensions"
                xmlns:p="http://primefaces.org/ui">


    <ui:define name="content">

        <h:panelGroup >
            <h:form  >
                <p:growl />
                <p:focus id="selectFocus" context="gpSelect" />
                <p:focus id="detailFocus" context="gpDetail" />



                <p:panel header="Manage Store Distributor" >
                    <h:panelGrid id ="gpVeda" columns="2" >

                        <h:panelGrid id="gpSelect" columns="1"  >
                            <p:panel >
                                <h:panelGrid id="gpSelectText" columns="1" >
                                    <p:autoComplete  id="lstSelect"  value="#{storeDealorController.current}" 
                                                     forceSelection="true"
                                                     completeMethod="#{storeDealorController.completeDealor}" 
                                                     var="vt" itemLabel="#{vt.name}" itemValue="#{vt}" >
                                        <f:ajax event="itemSelect" render="gpDetail gpDetailText smItems" execute="lstSelect" >
                                        </f:ajax>
                                    </p:autoComplete>     
                                    <p:selectOneMenu id="smItems" value="#{storeDealorController.current}" >
                                        <f:selectItem itemLabel="Select Distributor" ></f:selectItem>
                                        <f:selectItems value="#{storeDealorController.items}"
                                                       var="sd"
                                                       itemLabel="#{sd.name}"
                                                       itemValue="#{sd}"></f:selectItems>
                                        <f:ajax render="gpDetail gpDetailText lstSelect" execute="smItems" >
                                        </f:ajax>
                                    </p:selectOneMenu>
                                </h:panelGrid>
                                <h:panelGrid id="gpSelectButtons" columns="3"  >
                                    <h:commandButton id="btnAdd" value="Add" action="#{storeDealorController.prepareAdd()}" styleClass="buttons" >
                                        <f:ajax render="btnAdd  btnDelete btnSave   lstSelect gpDetail detailFocus gpDetailText" execute="" >
                                        </f:ajax>
                                    </h:commandButton>
                                    <h:commandButton id="btnDelete" onclick="if (!confirm('Are you sure you want to delete this record?'))
                                                return false;" action="#{storeDealorController.delete()}"  value="Delete"  >
                                    </h:commandButton>
                                </h:panelGrid>
                            </p:panel>
                        </h:panelGrid  >

                        <p:panel>
                            <h:panelGrid id="gpDetail" columns="1" >
                                <h:panelGrid id="gpDetailText" columns="2" >
                                    <h:outputText id="lblName" value="Name" ></h:outputText>
                                    <h:inputText autocomplete="off" id="txtName" value="#{storeDealorController.current.name}"  ></h:inputText>
                                    <h:outputText id="lblNameC" value="Printing Name" ></h:outputText>
                                    <h:inputText autocomplete="off" id="txtNameC" value="#{storeDealorController.current.chequePrintingName}"  ></h:inputText>
                                    <h:outputText id="lblCode" value="Code" ></h:outputText>
                                    <h:inputText autocomplete="off" id="txtCode" value="#{storeDealorController.current.institutionCode}"  ></h:inputText>
                                    <h:outputText  value="Adress" ></h:outputText>
                                    <h:inputText autocomplete="off"  value="#{storeDealorController.current.address}"  ></h:inputText>
                                    <h:outputText  value="Phone" ></h:outputText>
                                    <h:inputText autocomplete="off"  value="#{storeDealorController.current.phone}"  ></h:inputText>
                                    <h:outputText  value="Mobile" ></h:outputText>
                                    <h:inputText autocomplete="off"  value="#{storeDealorController.current.mobile}"  ></h:inputText>
                                    <h:outputText  value="Fax" ></h:outputText>
                                    <h:inputText autocomplete="off"  value="#{storeDealorController.current.fax}"  ></h:inputText>
                                    <h:outputText  value="E-mail" ></h:outputText>
                                    <h:inputText autocomplete="off"  value="#{storeDealorController.current.email}"  ></h:inputText>
                                    <p:separator ></p:separator>
                                    <p:separator ></p:separator>
                                    <h:outputText value="Contact Person Name" ></h:outputText>
                                    <h:inputText autocomplete="off"  value="#{storeDealorController.current.contactPerson.name}"  ></h:inputText>
                                    <h:outputText value="Contact Person Tel" ></h:outputText>
                                    <h:inputText autocomplete="off" value="#{storeDealorController.current.contactPerson.mobile}"  ></h:inputText>
                                    <h:outputText value="Contact Person Email" ></h:outputText>
                                    <h:inputText autocomplete="off" value="#{storeDealorController.current.contactPerson.email}"  ></h:inputText>
                                </h:panelGrid>
                                <h:panelGrid id="gpDetailButtons" columns="2">
                                    <h:commandButton id="btnSave" value="Save" action="#{storeDealorController.saveSelected()}" styleClass="buttons">
                                        <f:ajax render="btnAdd  btnDelete btnSave   lstSelect gpDetail selectFocus"  execute="gpDetail" >
                                        </f:ajax>
                                    </h:commandButton>
                                    <p:defaultCommand target="btnSave"/>
                                </h:panelGrid>
                            </h:panelGrid>
                        </p:panel>
                    </h:panelGrid>
                </p:panel>
                <p:panel header="Manage Store DistributorS List" id="panelPrint" styleClass="noBorder summeryBorder" >
                    <p:commandButton ajax="false" value="Print"  styleClass="noPrintButton" >
                        <p:printer target="panelPrint" />
                    </p:commandButton>
                    <p:commandButton ajax="false" value="Excel" styleClass="noPrintButton" >
                        <pe:exporter type="xlsx" target="tbl1" fileName="Store_Delors"  />
                    </p:commandButton>
                    <p:dataTable id="tbl1" value="#{storeDealorController.items}" var="d" rowIndexVar="i">
                        <p:column>
                            <f:facet name="header" >
                                <p:outputLabel value="No" />
                            </f:facet>
                            <p:outputLabel value="#{i+1}" />
                        </p:column>
                        <p:column>
                            <f:facet name="header" >
                                <p:outputLabel value="Distributor" />
                            </f:facet>
                            <p:outputLabel value="#{d.name}" />
                        </p:column>
                        <p:column>
                            <f:facet name="header" >
                                <p:outputLabel value="Distributor Printing Name" />
                            </f:facet>
                            <p:outputLabel value="#{d.chequePrintingName}" />
                        </p:column>
                        <p:column>
                            <f:facet name="header" >
                                <p:outputLabel value="Code" />
                            </f:facet>
                            <p:outputLabel value="#{d.institutionCode}" />
                        </p:column>
                        <p:column>
                            <f:facet name="header" >
                                <p:outputLabel value="Address" />
                            </f:facet>
                            <p:outputLabel value="#{d.address}" />
                        </p:column>
                        <p:column>
                            <f:facet name="header" >
                                <p:outputLabel value="Phone" />
                            </f:facet>
                            <p:outputLabel value="#{d.phone}" />
                        </p:column>
                        <p:column>
                            <f:facet name="header" >
                                <p:outputLabel value="Mobile" />
                            </f:facet>
                            <p:outputLabel value="#{d.mobile}" />
                        </p:column>
                        <p:column>
                            <f:facet name="header" >
                                <p:outputLabel value="Email" />
                            </f:facet>
                            <p:outputLabel value="#{d.email}" />
                        </p:column>
                    </p:dataTable>
                </p:panel>
            </h:form>

        </h:panelGroup>

    </ui:define>

</ui:composition>
